package com.ehu;

import com.ehu.api.IMUserAPI;
import com.ehu.comm.ClientContext;
import com.ehu.comm.EasemobRestAPIFactory;
import com.ehu.comm.body.IMUserBody;
import com.ehu.comm.wrapper.BodyWrapper;
import com.ehu.comm.wrapper.ResponseWrapper;

public class Main {

	public static void main(String[] args) throws Exception {
		EasemobRestAPIFactory factory = ClientContext.getInstance().init(ClientContext.INIT_FROM_PROPERTIES).getAPIFactory();

		IMUserAPI user = (IMUserAPI)factory.newInstance(EasemobRestAPIFactory.USER_CLASS);
		/*ChatMessageAPI chat = (ChatMessageAPI)factory.newInstance(EasemobRestAPIFactory.MESSAGE_CLASS);
		FileAPI file = (FileAPI)factory.newInstance(EasemobRestAPIFactory.FILE_CLASS);
		SendMessageAPI message = (SendMessageAPI)factory.newInstance(EasemobRestAPIFactory.SEND_MESSAGE_CLASS);
		ChatGroupAPI chatgroup = (ChatGroupAPI)factory.newInstance(EasemobRestAPIFactory.CHATGROUP_CLASS);
		ChatRoomAPI chatroom = (ChatRoomAPI)factory.newInstance(EasemobRestAPIFactory.CHATROOM_CLASS);

        ResponseWrapper fileResponse = (ResponseWrapper) file.uploadFile(new File("d:/logo.png"));
        String uuid = ((ObjectNode) fileResponse.getResponseBody()).get("entities").get(0).get("uuid").asText();
        String shareSecret = ((ObjectNode) fileResponse.getResponseBody()).get("entities").get(0).get("share-secret").asText();
        InputStream in = (InputStream) ((ResponseWrapper) file.downloadFile(uuid, shareSecret, false)).getResponseBody();
        FileOutputStream fos = new FileOutputStream("d:/logo1.png");
        byte[] buffer = new byte[1024];
        int len1 = 0;
        while ((len1 = in.read(buffer)) != -1) {
            fos.write(buffer, 0, len1);
        }
        fos.close();*/


		// Create a IM user
		/*		62
		65
		66
		69
		70
		76
		81
		82
		95
		110
		123
		124*/
/*		int[] t = new int[]{
				53,54,60,61,
				62,
				65,
				66,
				69,
				70,
				76,
				81,
				82,
				95,
				110,
				123,
				124
		};
		long[] l = new long[]{
				13567788854L,18221801956L,17301826024L,13764402478L,
				15601611642L,
				18862280170L,
				13701994819L,
				18721056207L,
				15356610083L,
				13310128657L,
				15555555555L,
				15968897036L,
				13122881031L,
				17017519707L,
				13666666666L,
				18862280171L
		};
		String hxUserName = "";
		String hxPassword = "";
		for(int i = 0 ; i < t.length ; i++){
			synchronized (Main.class) {
				hxUserName ="ehm"+System.currentTimeMillis()+t[i];
				hxPassword = l[i] *3 + 8080+"";
				System.out.println("hxUserName:"+hxUserName+"\n"+
						"hxPassword:"+hxPassword);
				BodyWrapper userBody = new IMUserBody(hxUserName, hxPassword);
				ResponseWrapper response = (ResponseWrapper)user.createNewIMUserSingle(userBody);
				System.out.println(response.getResponseBody()+"\n"+
						response.getMessages()+"\n"+
						response.getResponseStatus()+"\n"+
						"-------------------------------------------------------------");
				Main.class.wait(2000);
			}
		}
*/
		int guid = 65;
		long phone = 1555862282380L;
		String hxUserName = "ehm"+System.currentTimeMillis()+guid;
		String hxPassword = phone * 3 + 8080+"";
		System.out.println("hxUserName:"+hxUserName+"\n"+
				"hxPassword:"+hxPassword);
		BodyWrapper userBody = new IMUserBody(hxUserName, hxPassword);
		ResponseWrapper response = (ResponseWrapper)user.createNewIMUserSingle(userBody);
		System.out.println(response.getMessages()+"\n"+
				response.getResponseStatus());
		// user.getIMUsersBatch(1L,"");
		/*
		// Create some IM users
		List<IMUserBody> users = new ArrayList<IMUserBody>();
		users.add(new IMUserBody("User002", "123456", null));
		users.add(new IMUserBody("User003", "123456", null));
		BodyWrapper usersBody = new IMUsersBody(users);
		user.createNewIMUserBatch(usersBody);

		// Get a IM user
		user.getIMUsersByUserName("User001");

		// Get a fake user
		user.getIMUsersByUserName("FakeUser001");

		// Get 12 users
		user.getIMUsersBatch(null, null);
		 */
	}

}

